package com.yupi.springbootinit.mapper;

import com.yupi.springbootinit.model.entity.Chart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Entity com.yupi.springbootinit.model.entity.Chart
 */
public interface ChartMapper extends BaseMapper<Chart> {

    // 删除分表
    @Update("DROP TABLE IF EXISTS chart_${id}")
    void deleteTable(Long id);

    // 将用户上传文件数据分表创建并存入一个新表(建表)
    void createChartHeader(Long id, String[] headerData);

    // 插入用户上传文件数据分表数据
    void insertChartData(Map<String, Object> map);

    // 调用方法@todo
    // String chartId="1659210482555121666";
    // String querySql = String.format("select * from chart_%s",chartId);
    // List<Map<String,Object>>resultData = chartMapper.querychartData(querySql);
    // 查询用户数据对应的chartCData
    List<Map<String,Object>> queryChartData(Long querysql);

    // 查询数据库是否存在此表
    @Select("select COUNT(1) from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='caibi' AND TABLE_NAME = '${tableName}'")
    int queryTableNumber(@Param("tableName") String tableName);

    // 获取原始表格的数据
    @Select("select * from chart_#{id}")
    List<Map<String,Object>> selectCsvData(Long id);
}




